package com.hopechart.micro.util;

import org.springframework.util.StringUtils;

import com.google.common.base.CaseFormat;

/**
 * <p>
 * <br/>
 * String 工具类
 * </p>
 * 
 * @author daijiang@hopechart.com
 * @date 2017-10-30 09:46:47
 * @copyright 杭州鸿泉数字设备有限公司
 * @version V1.0.0
 */
public final class StringUtil extends StringUtils {

	public static boolean isNotEmpty(Object src) {
		return !isEmpty(src);
	}

	/**
	 * 格式 范例
     * LOWER_CAMEL lowerCamel
     * LOWER_HYPHEN lower-hyphen
     * LOWER_UNDERSCORE lower_underscore
     * UPPER_CAMEL UpperCamel
	 * UPPER_UNDERSCORE UPPER_UNDERSCORE
	 */

	/**
	 * user_name to userName
	 * 
	 * @param src
	 * @return
	 */
	public static String lowerUnderscoreToLowerCamel(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, src);
	}

	/**
	 * user-name to userName
	 * 
	 * @param src
	 * @return
	 */
	public static String lowerHyphenToLowerCamel(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.LOWER_HYPHEN.to(CaseFormat.LOWER_CAMEL, src);
	}

	/**
	 * user-name to UserName
	 * 
	 * @param src
	 * @return
	 */
	public static String lowerHyphenToLowerUnderscore(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, src);
	}

	/**
	 * user_name to UserName
	 * 
	 * @param src
	 * @return
	 */
	public static String lowerUnderscoreUpperCamel(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, src);
	}

	/**
	 * userName to user_name
	 * 
	 * @param src
	 * @return
	 */
	public static String lowerCamelToLowerUnderscore(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, src);
	}

	/**
	 * userName to USER_NAME
	 * 
	 * @param src
	 * @return
	 */
	public static String lowerCamelToUpperUnderscore(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, src);
	}

	/**
	 * userName to UserName
	 * 
	 * @param src
	 * @return
	 */
	public static String lowerCamelToUpperCamel(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, src);
	}

	/**
	 * UserName to userName
	 *
	 * @param src
	 * @return
	 */
	public static String upperCamelToLowerCamel(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, src);
	}

	/**
	 * USER_NAME to UserName
	 * 
	 * @param src
	 * @return
	 */
	public static String upperUnderscoreToUpperCamel(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, src);
	}

	/**
	 * USER_NAME to userName
	 * 
	 * @param src
	 * @return
	 */
	public static String upperUnderscoreToLowerCamel(String src) {
		if (isEmpty(src)) {
			return "";
		}
		return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, src);
	}

	public static void main(String[] args) {
		System.err.println("user_name to userName = " + lowerUnderscoreToLowerCamel("user_name"));
		System.err.println("user-name to userName = " + lowerHyphenToLowerCamel("user-name"));
		System.err.println("user-name to UserName = " + lowerHyphenToLowerUnderscore("user-name"));
		System.err.println("user_name to UserName = " + lowerUnderscoreUpperCamel("user_name"));
		System.err.println("-----------------------------------");
		System.err.println("userName to user_name = " + lowerCamelToLowerUnderscore("userName"));
		System.err.println("userName to USER_NAME = " + lowerCamelToUpperUnderscore("userName"));
		System.err.println("userName to UserName = " + lowerCamelToUpperCamel("userName"));
		System.err.println("UserName to userName = " + upperCamelToLowerCamel("UserName"));

		System.err.println("-----------------------------------");

		System.err.println("USER_NAME to UserName = " + upperUnderscoreToUpperCamel("USER_NAME"));
		System.err.println("USER_NAME to userName = " + upperUnderscoreToLowerCamel("USER_NAME"));

	}
}
